package com.shizhanzhe.qdd.base;

import android.content.Intent;
import android.support.multidex.MultiDexApplication;
import android.widget.Toast;

import com.dpuntu.downloader.DownloadManager;
import com.kingja.loadsir.core.LoadSir;
import com.mob.MobSDK;
import com.shizhanzhe.qdd.UpgradeActivity;
import com.shizhanzhe.qdd.utils.AdPreference;
import com.shizhanzhe.qdd.widget.ErrorCallback;
import com.shizhanzhe.qdd.widget.LoadingCallback;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;
import com.tencent.bugly.beta.UpgradeInfo;
import com.tencent.bugly.beta.upgrade.UpgradeListener;
import com.tencent.bugly.beta.upgrade.UpgradeStateListener;

/**
 * Created by zz9527 on 2018/10/12.
 */
public class BaseApplication extends MultiDexApplication {
    public static boolean starShare=false;
    @Override
    public void onCreate() {
        super.onCreate();
        new AdPreference(this);
        DownloadManager.initDownloader(this);

        Beta.autoInit = false;
        Beta.upgradeListener = new UpgradeListener() {
            @Override
            public void onUpgrade(int ret, UpgradeInfo strategy, boolean isManual, boolean isSilence) {
                if (strategy != null) {
                    Intent i = new Intent();
                    i.setClass(getApplicationContext(), UpgradeActivity.class);
                    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(i);
                } else {
                    Toast.makeText(BaseApplication.this, "当前为最新版本", Toast.LENGTH_SHORT).show();
                }
            }
        };

        /* 设置更新状态回调接口 */
        Beta.upgradeStateListener = new UpgradeStateListener() {
            @Override
            public void onUpgradeSuccess(boolean isManual) {
                //Toast.makeText(getApplicationContext(),"UPGRADE_SUCCESS",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onUpgradeFailed(boolean isManual) {
                //Toast.makeText(getApplicationContext(),"UPGRADE_FAILED",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onUpgrading(boolean isManual) {
                //Toast.makeText(getApplicationContext(),"UPGRADE_CHECKING",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onDownloadCompleted(boolean b) {

            }

            @Override
            public void onUpgradeNoVersion(boolean isManual) {
                //Toast.makeText(getApplicationContext(),"UPGRADE_NO_VERSION",Toast.LENGTH_SHORT).show();
            }
        };
        Bugly.init(getApplicationContext(), "a510012ecd", true);
        LoadSir.beginBuilder()
                .addCallback(new ErrorCallback())//添加各种状态页
                .addCallback(new LoadingCallback())
                .setDefaultCallback(LoadingCallback.class)//设置默认状态页
                .commit();
    }
}
